import javax.sound.sampled.*;
import java.net.*;

public class AudioReceiver {
    public static void main(String[] args) throws Exception {
        int port = 50005;
        DatagramSocket socket = new DatagramSocket(port);

        SourceDataLine line = AudioUtil.getSourceDataLine();
        line.start();

        byte[] buffer = new byte[1024];
        while (true) {
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
            socket.receive(packet);
            System.out.println("Received packet with size: " + packet.getLength());
            line.write(buffer, 0, packet.getLength());
        }
    }
}
